/* CodeBuilder代码生成器 创建时间：2011-11-20 21:43:36 */
using System;
using System.Data;
using System.Text;
using System.Data.SqlClient;
using System.Collections.Generic;
using Maticsoft.DBUtility;
namespace DAL
{
	/// <summary>
	/// 数据访问类:V_Grouping 
	/// </summary>
	public partial class V_Grouping
	{
		public V_Grouping()
		{}
		#region  Method

        /// <summary>
		/// 是否存在该条件记录
		/// </summary>
        /// <param name="strWhere">Where条件</param>
        /// <returns>bool:True/False</returns>
		public bool Exists(string strWhere)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select count(1) from V_Grouping");
			if(!string.IsNullOrEmpty(strWhere))
            {
                strSql.Append(" where " + strWhere);
            }
			return DbHelperSQL.Exists(strSql.ToString(),null);
		}

        /// <summary>
        /// 获取数量
        /// </summary>
        /// <returns>总记录数</returns>
        public int Count()
        { 
            return Count(null);
        }

        /// <summary>
        /// 根据条件获取数量
        /// </summary>
        /// <param name="strWhere">Where条件</param>
        /// <returns>记录数</returns>
        public int Count(string strWhere)
        { 
            string strSql = "select count(*) from V_Grouping";
            if(!string.IsNullOrEmpty(strWhere))
            {
                strSql += " where " + strWhere;
            }
            object obj = DbHelperSQL.GetSingle(strSql,null);
            if (obj == null)
            {
                return 0;
            }
            else
            {
                return Convert.ToInt32(obj);
            }
        }

        /// <summary>
		/// 得到一个对象实体
		/// </summary>
        /// <param name="strWhere">Where条件</param>
		public Model.V_Grouping GetModelBystrWhere(string strWhere)
		{
			
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select  top 1 ID,UserID,Classification,Content,UpNum,DownNum,AddTime,Lang,UserName,HeahImagePath,NickName from V_Grouping ");
			if(!string.IsNullOrEmpty(strWhere))
            {
                strSql.Append(" where "+ strWhere);
            }

			Model.V_Grouping model=new Model.V_Grouping();
			DataSet ds=DbHelperSQL.Query(strSql.ToString(),null);
			if(ds.Tables[0].Rows.Count>0)
			{
                if(ds.Tables[0].Rows[0]["ID"].ToString()!="")
				{
                    model.ID=int.Parse(ds.Tables[0].Rows[0]["ID"].ToString());
				}
                if(ds.Tables[0].Rows[0]["UserID"].ToString()!="")
				{
                    model.UserID=int.Parse(ds.Tables[0].Rows[0]["UserID"].ToString());
				}
                if(ds.Tables[0].Rows[0]["Classification"].ToString()!="")
				{
                    model.Classification=ds.Tables[0].Rows[0]["Classification"].ToString();
				}
                if(ds.Tables[0].Rows[0]["Content"].ToString()!="")
				{
                    model.Content=ds.Tables[0].Rows[0]["Content"].ToString();
				}
                if(ds.Tables[0].Rows[0]["UpNum"].ToString()!="")
				{
                    model.UpNum=int.Parse(ds.Tables[0].Rows[0]["UpNum"].ToString());
				}
                if(ds.Tables[0].Rows[0]["DownNum"].ToString()!="")
				{
                    model.DownNum=int.Parse(ds.Tables[0].Rows[0]["DownNum"].ToString());
				}
                if(ds.Tables[0].Rows[0]["AddTime"].ToString()!="")
				{
                    model.AddTime=DateTime.Parse(ds.Tables[0].Rows[0]["AddTime"].ToString());
				}
                if(ds.Tables[0].Rows[0]["Lang"].ToString()!="")
				{
                    model.Lang=ds.Tables[0].Rows[0]["Lang"].ToString();
				}
                if(ds.Tables[0].Rows[0]["UserName"].ToString()!="")
				{
                    model.UserName=ds.Tables[0].Rows[0]["UserName"].ToString();
				}
                if(ds.Tables[0].Rows[0]["HeahImagePath"].ToString()!="")
				{
                    model.HeahImagePath=ds.Tables[0].Rows[0]["HeahImagePath"].ToString();
				}
                if(ds.Tables[0].Rows[0]["NickName"].ToString()!="")
				{
                    model.NickName=ds.Tables[0].Rows[0]["NickName"].ToString();
				}
                                return model;
			}
			else
			{
				return null;
			}
		}

		/// <summary>
		/// 获得数据列表
		/// </summary>
        /// <param name="strWhere">Where条件</param>
        /// <returns>数据集</returns>
		public DataSet GetList(string strWhere)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select ID,UserID,Classification,Content,UpNum,DownNum,AddTime,Lang,UserName,HeahImagePath,NickName ");
			strSql.Append(" FROM V_Grouping ");
			if(!string.IsNullOrEmpty(strWhere))
			{
				strSql.Append(" where "+strWhere);
			}
			return DbHelperSQL.Query(strSql.ToString());
		}

		/// <summary>
		/// 获得前几行数据
		/// </summary>
        /// <param name="Top">条数</param>
        /// <param name="strWhere">Where条件</param>
        /// <param name="filedOrder">filedOrder排序</param>
        /// <returns>数据集</returns>
		public DataSet GetList(int Top,string strWhere,string filedOrder)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select ");
			if(Top>0)
			{
				strSql.Append(" top "+Top.ToString());
			}
			strSql.Append(" ID,UserID,Classification,Content,UpNum,DownNum,AddTime,Lang,UserName,HeahImagePath,NickName ");
			strSql.Append(" FROM V_Grouping ");
			if(!string.IsNullOrEmpty(strWhere))
			{
				strSql.Append(" where "+strWhere);
			}
            if(!string.IsNullOrEmpty(filedOrder))
            {
			    strSql.Append(" order by " + filedOrder);
            }
			return DbHelperSQL.Query(strSql.ToString());
		}

		
		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		public Model.PageData GetList(int PageSize,int PageIndex,string strWhere,string filedOrder)
		{
            SqlParameter[] parameters = {
                    new SqlParameter("@sqlstr", SqlDbType.NVarChar, 4000),
                    new SqlParameter("@pageindex", SqlDbType.Int),
                    new SqlParameter("@pagesize", SqlDbType.Int),
                    };
            StringBuilder strSql=new StringBuilder("select * from V_Grouping ");
            if(!string.IsNullOrEmpty(strWhere))
			{
				strSql.Append(" where "+strWhere);
			}
            if(!string.IsNullOrEmpty(filedOrder))
            {
			    strSql.Append(" order by " + filedOrder);
            }
            parameters[0].Value = strSql.ToString();
            parameters[1].Value = PageIndex;
            parameters[2].Value = PageSize;

            DataSet ds = DbHelperSQL.RunProcedure("SP_pagination", parameters, "ds");
            DataSet newds = new DataSet();
            newds.Tables.Add(ds.Tables[2].Copy());
            Model.PageData data = new Model.PageData();
            data.PageIndex = PageIndex;
            data.PageSize = PageSize;
            data.Count =  Convert.ToInt32(ds.Tables[1].Rows[0]["Count"]);
            data.DataSoure = newds;

            return data;
		}

		#endregion  Method
	}
}

